﻿XIncludeFile "Function.pb"
XIncludeFile "ImageButton.pb"


;==============================函数类型===============================
 Prototype.l WindIcon(This)
 Prototype.l WindUpData(This,Hwnd)

;==================================常数==================================
Enumeration
 #Style=1
 #Visible=2
 #Enabled=4
 
 #Gdip_Window_NoClose=8
 #Gdip_Window_NoMax=16
 #Gdip_Window_NoMin=32
 
EndEnumeration

;==============================窗口结构==============================
Structure GdipWnd Extends PWnd
  Window.l      ;窗口ID
  Icon.l        ;窗口图标
  Style.B       ;窗口类型
  RawWidth.l    
  RawHeight.l   
  MinBox.l      ;最小化按钮控件
  MaxBox.l      ;最大化按钮控件
  EnableMax.b   ;最大化按钮是否可用
  CloseBox.l    ;关闭按钮控件
  DrawType.l
  wIcon.WindIcon
  wUpData.WindUpData
EndStructure

;================================变量===========================================


;================================函数===========================================

Procedure IWndIcon(*Window.GdipWnd) ;绘制窗口图标
  With *Window\Creat
     GdipGetImageWidth(\UpLeft,@Width)     ;获得左上角窗口背景图像宽度
     GdipGetImageHeight(\UpLeft,@Height)   ;获得右上角窗口背景图像宽度
     GdipGetImageGraphicsContext(\ImageBack,@Graphics)   
       GdipSetCompositingMode(Graphics,#CompositingModeSourceCopy)
       GdipDrawImageRect(Graphics,\UpLeft,0,0,Width,Height)
       
       GdipSetCompositingMode(Graphics,#CompositingModeSourceOver)
       GdipDrawImageRectI(Graphics,*Window\Icon,Width-23,Height-23,18,18)
 
     GdipDeleteGraphics(Graphics)
  EndWith
EndProcedure

Procedure IWndText(*Window.GdipWnd,Text.s) ;绘制窗口文本
  With *Window\Creat
     X=GdipImageWidth(\UpLeft)
    ;Y=0
     GdipGetImageWidth(\ImageBack,@Width)
     Width-X-GdipImageWidth(\UpRight)
     GdipGetImageHeight(\Up,@Height)
       GdipGetImageGraphicsContext(\ImageBack,@Graphics)
       GdipSetCompositingMode(Graphics,#CompositingModeSourceCopy)
       
       GdipCreateTexture(\Up,#WrapModeTileFlipX,@Brush)
       GdipFillRectangle(Graphics,Brush,X,0,Width,Height)
       GdipDeleteBrush(Brush)

       GdipPathText(Graphics,\Text\Text,\Text\X,\Text\Y,\Text\Width,\Text\Height-2,\Text\FontName,\Text\FontSize,\Text\FontStyle,\Text\TextColor,\Text\PenColor,\Text\PenWidth,\Text\Align,\Text\Style)
     GdipDeleteGraphics(Graphics)
  EndWith
EndProcedure

Procedure IWndSize(*Window.GdipWnd,Width,Height) ;创建窗口
  *Window\Width =Width
  *Window\Height=Height
  With *Window\Creat
    GdipDisposeImage(\ImageBack)
    GdipCreateBitmapFromScan0(Width,Height,0,#GDIPLUS_PIXELFORMAT_32bppARGB, 0,@\ImageBack)
     GdipGetImageGraphicsContext(\ImageBack,@Graphics)
      GdipSetCompositingMode(Graphics,#CompositingModeSourceCopy)
      GdipImageDraw(Graphics,\UpRight,Width-GdipImageWidth(\UpRight),0)
      GdipImageTile(Graphics,\Right,Width-GdipImageWidth(\Right),GdipImageHeight(\UpRight),GdipImageWidth(\Right),Height-GdipImageHeight(\UpRight)-GdipImageHeight(\DownRight))
      GdipImageDraw(Graphics,\DownRight,Width-GdipImageWidth(\DownRight),Height-GdipImageHeight(\DownRight)) 
      GdipImageTile(Graphics,\Down,GdipImageWidth(\DownLeft),Height-GdipImageHeight(\Down),Width-GdipImageWidth(\DownLeft)-GdipImageWidth(\DownRight),GdipImageHeight(\Down))
      GdipImageDraw(Graphics,\DownLeft,0,Height-GdipImageHeight(\DownLeft))
      GdipImageTile(Graphics,\Left,0,GdipImageHeight(\UpLeft),GdipImageWidth(\Left),Height-GdipImageHeight(\Upleft)-GdipImageHeight(\DownLeft))
      GdipImageTile(Graphics,\Center,GdipImageWidth(\Left),GdipImageHeight(\Up),Width-GdipImageWidth(\Left)-GdipImageWidth(\Right),Height-GdipImageHeight(\Up)-GdipImageHeight(\Down))
    GdipDeleteGraphics(Graphics)
    \Text\X=GdipImageWidth(\UpLeft)
    \Text\Width=GdipImageWidth(\ImageBack)-GdipImageWidth(\UpRight)-\Text\X
    \Text\Height=GdipImageHeight(\Up)-\Text\Y
  EndWith
  *Window\wIcon(*Window)
  *Window\wText(*Window,"")
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Procedure IWndLoad(*Window.GdipWnd) ;当窗口加载时
  *Gadget.PWnd=*Window\Gadget
  While *Gadget    
     *Gadget\wLoad(*Gadget)
     *Gadget= *Gadget\DownList
  Wend
  GdipDisposeImage(*Window\Creat\ImageBack)
  If *Window\Image
     GdipCloneImage(*Window\Image,@*Window\Creat\ImageBack)
  Else 
     GdipCreateBitmapFromScan0(*Window\Width,*Window\Height,0,#GDIPLUS_PIXELFORMAT_32bppARGB, 0,@*Window\Creat\ImageBack)
     *Window\wSize(*Window,*Window\Width+8,*Window\Height+GetSystemMetrics_(#SM_CYCAPTION)+8)
  EndIf 
EndProcedure

Procedure IWndDraw(*Window.GdipWnd,*Gadget.PWnd,*cRect.RECT) ;绘制控件
  GdipGetImageGraphicsContext(*Window\Creat\ImageBack,@Graphics)
  
  ;判断是否显视 最小化.最大化,关闭按钮
  If *Window\Image And (*Gadget=*Window\MinBox Or *Gadget=*Window\MaxBox Or *Gadget=*Window\CloseBox)
    *Gadget=*Window\MinBox
    *Gadget=*Gadget\DownList
  EndIf 
  
  If *Gadget And *Gadget\Draw
     GdipGetImageWidth(*Gadget\Creat\ImageBack,@Width)
     GdipGetImageHeight(*Gadget\Creat\ImageBack,@Height)
     GdipSetCompositingMode(Graphics,#CompositingModeSourceCopy)
     GdipDrawImageRectRectI(Graphics,*Gadget\Draw,*Gadget\X,*Gadget\Y,Width,Height,0,0,Width,Height, #UnitPixel,#Null, #Null, #Null)
  EndIf 

  While *Gadget 
     If *Window\DrawType <> #WM_SIZE
       *Gadget\wDraw(*Gadget,*Gadget\Gadget,@*Gadget\X)  
     EndIf
     If *cRect\left < *Gadget\X
       X = *Gadget\X
     Else
       X = *cRect\left
     EndIf 
     
     If *cRect\top < *Gadget\Y
       Y = *Gadget\Y
     Else 
       Y = *cRect\top
     EndIf 
     
     If *cRect\right+*cRect\left > *Gadget\Width+ *Gadget\X
      Width =  *Gadget\Width+ *Gadget\X-X
     Else 
       Width = *cRect\right+*cRect\left-X
     EndIf 
     
     If *cRect\bottom+*cRect\top > *Gadget\Height+ *Gadget\Y
       Height = *Gadget\Height+ *Gadget\Y-Y
     Else 
       Height = *cRect\bottom+*cRect\top-Y
     EndIf 

     If Width >0 And Height >0 
       If *Gadget\ModeSource=#CompositingModeSourceOver
         If Not *Gadget\Draw
           GdipGetImageWidth(*Gadget\Creat\ImageBack,@Width)
           GdipGetImageHeight(*Gadget\Creat\ImageBack,@Height)
           GdipCreateBitmapFromScan0(*Gadget\Width,*Gadget\Height,0,#GDIPLUS_PIXELFORMAT_32bppARGB, 0,@*Gadget\Draw)
         EndIf 
         GdipGetImageGraphicsContext(*Gadget\Draw,@dGraphics)
           GdipSetCompositingMode(dGraphics,#CompositingModeSourceCopy)
           GdipDrawImageRectRectI(dGraphics,*Window\Creat\ImageBack,X-*Gadget\X, Y-*Gadget\Y,Width,Height,X,Y,Width,Height, #UnitPixel,#Null, #Null, #Null)
         GdipDeleteGraphics(dGraphics)
       EndIf 
       GdipSetCompositingMode(Graphics,*Gadget\ModeSource)
       GdipDrawImageRectRectI(Graphics,*Gadget\Creat\ImageBack,X,Y,Width,Height,X-*Gadget\X, Y-*Gadget\Y,Width,Height, #UnitPixel,#Null, #Null, #Null)
     EndIf 
    *Gadget=*Gadget\DownList
  Wend
  GdipDeleteGraphics(Graphics)
EndProcedure

Procedure IWndEvent(*Window.GdipWnd,hWnd, uMsg, wParam, lParam)
  Events=#PB_ProcessPureBasicEvents 
  Select uMsg
    Case #WM_LBUTTONDOWN
      *Window\OnGadget=*Window
      If HIWORD(lParam)< 33 And *Window\RawWidth=0
        PostMessage_(hWnd, #WM_SYSCOMMAND,   #SC_MOVE   +   #HTCAPTION,0)
      EndIf 
   ;EndCase 
   
    Case #WM_LBUTTONDBLCLK
      If HIWORD(lParam)< 33 
         If *Window\EnableMax
           If *Window\RawWidth Or *Window\RawHeight
             SendMessage_(hWnd, #WM_SYSCOMMAND, #SC_RESTORE ,0)
           Else 
             SendMessage_(hWnd, #WM_SYSCOMMAND, #SC_MAXIMIZE ,0)
           EndIf
         EndIf  
      EndIf
    ;EndCase 
  EndSelect
  ProcedureReturn  Events
EndProcedure

Procedure IWndUpData(*Window.GdipWnd,Hwnd)
  DeleteObject_(*Window\Draw)
  GdipCreateHBITMAPFromBitmap(*Window\Creat\ImageBack,@*Window\Draw,0)
  SetWindowLong_(hWnd,#GWL_EXSTYLE,GetWindowLong_(hWnd,#GWL_EXSTYLE)|#WS_EX_LAYERED) 
  hDC =CreateCompatibleDC_(#Null)
  Ogject=SelectObject_(hDC,*Window\Draw)
    sz.SIZE 
    sz\cx = *Window\Width
    sz\cy = *Window\Height
    BlendMode.BLENDFUNCTION 
    BlendMode\SourceConstantAlpha = 255 
    BlendMode\AlphaFormat = 1 
  UpdateLayeredWindow_(hWnd, 0, 0, @sz, hDC, @ContextOffset.POINT , 0, @BlendMode, 2) 
  DeleteObject_(Ogject)
  DeleteDC_(hDC )
EndProcedure

Procedure IWndMin(*Button.GdipButton,hWnd, uMsg, wParam, lParam)
  PostMessage_(hWnd, #WM_SYSCOMMAND, #SC_MINIMIZE,0)
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Procedure IWndMax(*Button.GdipButton,hWnd, uMsg, wParam, lParam)
   *Window.GdipWnd=GetWindow(Hwnd)
  If *Window\RawWidth Or *Window\RawHeight
     SendMessage_(hWnd, #WM_SYSCOMMAND, #SC_RESTORE ,0)
  Else 
     SendMessage_(hWnd, #WM_SYSCOMMAND, #SC_MAXIMIZE ,0)
  EndIf 
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Procedure IWndClose(*Button.GdipButton,hWnd, uMsg, wParam, lParam)
  SendMessage_(hWnd,#WM_CLOSE, 0, 0)
  ProcedureReturn #PB_ProcessPureBasicEvents 
EndProcedure

Procedure IWndFree(*Window.GdipWnd)
  *Gadget.PWnd=*Window\Gadget
  While *Gadget 
    T=*Gadget\DownList
     *Gadget\wFree(*Gadget)
     *Gadget= T
  Wend
  GdipDisposeImage(*Window\Icon)  
  GdipDisposeImage(*Window\Image)  ;当前绘制的图片
  DeleteObject_(*Window\Draw)
  GdipDisposeImage(*Window\Creat\ImageBack)   ;绘制缓冲
  GdipDisposeImage(*Window\Creat\Center)   ;绘制缓冲
  GdipDisposeImage(*Window\Creat\Left)   ;绘制缓冲
  GdipDisposeImage(*Window\Creat\DownLeft)   ;绘制缓冲
  GdipDisposeImage(*Window\Creat\Down)   ;绘制缓冲
  GdipDisposeImage(*Window\Creat\DownRight)   ;绘制缓冲
  GdipDisposeImage(*Window\Creat\Right)   ;绘制缓冲
  GdipDisposeImage(*Window\Creat\UpRight)   ;绘制缓冲
  GdipDisposeImage(*Window\Creat\Up)   ;绘制缓冲
  GdipDisposeImage(*Window\Creat\UpLeft)   ;绘制缓冲
  CloseWindow(*Window\Window)
  DeleteWindowList(*Window)
EndProcedure

Procedure GdipOpenWindow(Image,X,Y,Width,Height,Caption.s,Style=6,Mode=0,Parent=0) 
  *Window.GdipWnd=AddWindowList(@GdipWindow,SizeOf(GdipWnd))
  If -1 = Image
    GdipCreateBitmapFromScan0(Width,Height,0,#GDIPLUS_PIXELFORMAT_32bppARGB, 0,@*Window\Image)
  ElseIf Image
    GdipCloneImage(Image,@*Window\Image)
    GdipGetImageWidth(Image,@Width )
    GdipGetImageHeight(Image,@Height)
  Else
    With *Window\Creat
      \UpLeft=GdipCatchImage(?ImageWindowUpLeft,?ImageWindowUp-?ImageWindowUpLeft)
      \UP=GdipCatchImage(?ImageWindowUp,?ImageWindowUpRight-?ImageWindowUp)
      \UpRight=GdipCatchImage(?ImageWindowUpRight,?ImageWindowRight-?ImageWindowUpRight)
      \Right=GdipCatchImage(?ImageWindowRight,?ImageWindowDownRight-?ImageWindowRight)
      \DownRight=GdipCatchImage(?ImageWindowDownRight,?ImageWindowDown-?ImageWindowDownRight)
      \Down=GdipCatchImage(?ImageWindowDown,?ImageWindowDownLeft-?ImageWindowDown)
      \DownLeft=GdipCatchImage(?ImageWindowDownLeft,?ImageWindowLeft-?ImageWindowDownLeft)
      \Left=GdipCatchImage(?ImageWindowLeft,?ImageWindowCenter-?ImageWindowLeft)
      \Center=GdipCatchImage(?ImageWindowCenter,?ImageWindowMin-?ImageWindowCenter)
      iWidth =GdipImageWidth( \UpLeft)+GdipImageWidth(\UpRight)
      iHeight=GdipImageHeight(\Up)   +GdipImageHeight(\Down)
      If Width <iWidth : Width =iWidth : EndIf
      If Height<iHeight: Height=iHeight: EndIf
    EndWith
  EndIf 
  With *Window\Creat\Text
    \Text=Caption
    \FontName="宋体"
    \FontSize=15
    \FontStyle=1
    \TextColor=$FF000000
    \Align= #GD_TextLineAlignDown
    \Style=4
    \Y=20
  EndWith
  With *Window
    *Wind.GdipWnd=GdipWindow
    While *Wind
      If  *Wind = Parent
         ParentID=WindowID(*Wind\Window)
         Break
      EndIf 
      *Wind=*Wind\DownList
    Wend 
    \Window=OpenWindow(#PB_Any,X,Y,Width,Height,Caption,Mode | #PB_Window_BorderLess | #PB_Window_Invisible,ParentID)
    \Width=Width
    \Height=Height
    \Visible=IsVal(Style,#Visible)
    \Enabled=IsVal(Style,#Enabled)
    \Type=#Window
    \Style=IsVal(Style,1)
    \HostGadget=@GdipWindow
    Icon=LoadIcon_(GetModuleHandle_(#Null),1)
    If Not Icon
      Icon=LoadIcon_(0,#IDI_APPLICATION)
    EndIf 
    GdipCreateBitmapFromHICON(Icon,@*Window\Icon)
    
    MinMaxClose = GdipCatchImage(?ImageWindowClose,?ImageWindowEnd-?ImageWindowClose)
    GdipGetImageWidth(MinMaxClose,@tWidth)
    Width-tWidth/4-5
    If IsVal(Style,#Gdip_Window_NoClose)
      GadgetStype= #Visible 
    Else
      GadgetStype= #Visible | #Enabled
    EndIf 
    \CloseBox=GdipCreateButton(*Window,MinMaxClose,Width,9,0,0,"关闭",GadgetStype,#CompositingModeSourceCopy)
    *TButton.GdipButton=\CloseBox
    *TButton\wClick=@IWndClose()
     CopyMemory(\CloseBox,T.GdipButton,SizeOf(GdipButton))
    GdipDisposeImage(MinMaxClose)
    MinMaxClose = GdipCatchImage(?ImageWindowMax,?ImageWindowClose-?ImageWindowMax)
    GdipGetImageWidth(MinMaxClose,@tWidth)
    Width-tWidth/4
    If IsVal(Style,#Gdip_Window_NoMax)
      GadgetStype= #Visible 
    Else
      GadgetStype= #Visible | #Enabled
      \EnableMax=1
    EndIf 
    \MaxBox=GdipCreateButton(*Window,MinMaxClose,Width,9,0,0,"最大化",GadgetStype,#CompositingModeSourceCopy)
    *TButton.GdipButton=\MaxBox
    *TButton\wClick=@IWndMax()
    GdipDisposeImage(MinMaxClose)
    MinMaxClose = GdipCatchImage(?ImageWindowMin,?ImageWindowMax-?ImageWindowMin)
    GdipGetImageWidth(MinMaxClose,@tWidth)
    Width-tWidth/4
    If IsVal(Style,#Gdip_Window_NoMin)
      GadgetStype= #Visible 
    Else
      GadgetStype= #Visible | #Enabled
    EndIf 
    \MinBox=GdipCreateButton(*Window,MinMaxClose,Width,9,0,0,"最小化",GadgetStype,#CompositingModeSourceCopy)
    *TButton.GdipButton=\MinBox
    *TButton\wClick=@IWndMin()
    GdipDisposeImage(MinMaxClose)
    \OnGadget= *Window
    \wLoad=@IWndLoad()
    \wDraw=@IWndDraw()
    \wEvent=@IWndEvent()
    \wFree=@IWndFree()
    \wSize=@IWndSize()
    \wIcon=@IWndIcon()
    \wText=@IWndText()  
    \wUpData=@IWndUpData()  
  EndWith
  ProcedureReturn *Window
EndProcedure

Procedure GdipShowWindow(*GdipHwnd.GdipWnd,Mode=1)
  If IsWindow(*GdipHwnd\Window)
    Hwnd=WindowID(*GdipHwnd\Window)

    SetWindowPos_(Hwnd,#HWND_TOPMOST,0,0,0,0,#SWP_NOSIZE | #SWP_NOMOVE);
    PostMessage_(Hwnd,#WM_LoadWindow,0,0)
    ShowWindow_(Hwnd,Mode)
  EndIf 
EndProcedure

Procedure GdipSetWindowText(*GdipHwnd.GdipWnd,Text.s)
  If IsWindow(*GdipHwnd\Window)
    Hwnd=WindowID(*GdipHwnd\Window)
    SetWindowText_(Hwnd,Text)
  EndIf 
EndProcedure

Procedure GdipSetWindowIcon(*GdipHwnd.GdipWnd,Icon)
  If IsWindow(*GdipHwnd\Window)
    Hwnd=WindowID(*GdipHwnd\Window)
    PostMessage_(Hwnd,#WM_SETICON,0,Icon) 
  EndIf 
EndProcedure

Procedure WinCallback(hWnd, uMsg, wParam, lParam) 
  Events=#PB_ProcessPureBasicEvents 
  *Window.GdipWnd=GetWindow(Hwnd)
  If Not *Window
     ProcedureReturn Events
  EndIf 
  *Window\DrawType=uMsg
  If Not *Window\UpGadget
     *Window\UpGadget=*Window
  EndIf 
  Select uMsg
    Case #WM_LoadWindow
     *Window\wLoad(*Window.GdipWnd)
     SendMessage_(Hwnd,#WM_Draw,*Window\Gadget, @*Window\X)
     ;EndCase
    Case #WM_Draw
      *Window\wDraw(*Window,wParam, lParam)
      SendMessage_(Hwnd,#WM_UpDataWindow,0,0)
     ;EndCase
    Case #WM_UpDataWindow
      *Window\wUpData(*Window,Hwnd)
      ;EndCase
    Case #WM_SIZE 
      If Not *Window\Image
        Events= *Window\wSize(*Window,LOWORD(lParam),HIWORD(lParam))
        *pBox.PWnd=*Window\CloseBox
        tWidht=LOWORD(lParam)-*pBox\Width-13
        *pBox\X=tWidht
        
        *pBox.PWnd=*Window\MaxBox
        tWidht-*pBox\Width
        *pBox\X=tWidht
        
        *pBox.PWnd=*Window\MinBox
        tWidht-*pBox\Width
        *pBox\X=tWidht 
        SendMessage_(Hwnd,#WM_Draw,*Window\Gadget,@*Window\X)
      EndIf 
     ;EndCase
    Case #WM_SETICON
      If Not *Window\Image
        GdipDisposeImage(*Window\Icon)
        GdipCreateBitmapFromHICON(lParam,@*Window\Icon)
        *Window\wIcon(*Window)
        SendMessage_(Hwnd,#Wm_UpDataWindow,0,0) 
      EndIf 
    ;EndCase
    Case #WM_SETTEXT
      If Not *Window\Image
        *Window\Creat\Text\text=PeekS(lParam)
        *Window\wText(*Window,"")
        SendMessage_(Hwnd,#Wm_UpDataWindow,0,0) 
      EndIf 
    ;EndCase
    Case #WM_GETMINMAXINFO
      *pMinMax.MINMAXINFO = lParam
;       *pMinMax\ptMinTrackSize\x=GdipImageWidth( *Window\Creat\UpLeft)+GdipImageWidth(*Window\Creat\UpRight)+10
;       *pMinMax\ptMinTrackSize\y=GetSystemMetrics_(#SM_CYCAPTION)+10
       *pMinMax\ptMinTrackSize\x=100
       *pMinMax\ptMinTrackSize\y=50
      *pMinMax\ptMaxTrackSize\X=GetSystemMetrics_(#SM_CXSCREEN)
      *pMinMax\ptMaxTrackSize\y=GetSystemMetrics_(#SM_CYSCREEN)
     Result = 0
      
    Case #WM_MOVE,#WM_LBUTTONDOWN,#WM_LBUTTONUP,#WM_RBUTTONDOWN,#WM_RBUTTONUP,#WM_MOUSEMOVE,#WM_LBUTTONDBLCLK
     *Gadget.PWnd=*Window\NewGadget
     While *Gadget
       If *Gadget\wIsLoca
         If *Gadget\wIsLoca(*Gadget,hWnd,LOWORD(lParam),HIWORD(lParam))
            If *Window\UpGadget<>*Gadget
              *UpGadget.PWnd=*Window\UpGadget
              *UpGadget\wEvent(*UpGadget,hWnd, #WM_MouseToLeave, wParam, lParam)
              uMsg=#WM_MouseToEnte   
            EndIf 
            *Window\UpGadget=*Gadget
            *Gadget\wEvent(*Gadget,hWnd, uMsg, wParam, lParam)
            ProcedureReturn Events
         EndIf 
       EndIf
       *Gadget=*Gadget\UpList
     Wend
     If *Window <> *Window\UpGadget
        *UpGadget.PWnd=*Window\UpGadget
        *UpGadget\wEvent(*UpGadget,hWnd, #WM_MouseToLeave, wParam, lParam)
        *Window\UpGadget= *Window
     EndIf 
     *Window\wEvent(*Window,hWnd, uMsg, wParam, lParam)
    ;EndCase
    Case #WM_SYSCOMMAND
      Select wParam
        Case #SC_MAXIMIZE
          *Window\RawWidth= *Window\Width
          *Window\RawHeight=*Window\Height
          PostMessage_(hWnd,#WM_SIZE ,0,LongPoint(GetSystemMetrics_(#SM_CXFULLSCREEN),GetSystemMetrics_(#SM_CYFULLSCREEN)+GetSystemMetrics_(#SM_CYCAPTION)))
       ;EndCase
        Case #SC_RESTORE
          PostMessage_(hWnd,#WM_SIZE ,0,LongPoint(*Window\RawWidth,*Window\RawHeight))
          *Window\RawWidth=0
          *Window\RawHeight=0
        ;EndCase
        Case #SC_MINIMIZE
          *Window\RawWidth= *Window\Width
          *Window\RawHeight=*Window\Height
        ;EndCase
      EndSelect
    ;EndCase
    Case #WM_CHAR
      *Gadget.PWnd=*Window\OnGadget
      If *Gadget
         *Gadget\wEvent(*Gadget,hWnd, uMsg, wParam, lParam)
      EndIf 
    ;EndCase


  EndSelect
  ProcedureReturn Events
EndProcedure 

Procedure GdipCloseWindow(*GdipHwnd.GdipWnd)
  *Window.GdipWnd=GdipWindow
  While *Window
    If  *Window = *GdipHwnd
       *GdipHwnd\wFree(*GdipHwnd)
       Break
    EndIf 
    *Window=*Window\DownList
  Wend 
EndProcedure

SetWindowCallback(@WinCallback())

DataSection
ImageWindowUpLeft:
   IncludeBinary "Image\Window\UpLeft.png"
ImageWindowUp:
   IncludeBinary "Image\Window\Up.png"
ImageWindowUpRight:
   IncludeBinary "Image\Window\UpRight.png"
ImageWindowRight:
   IncludeBinary "Image\Window\Right.png"
ImageWindowDownRight:
   IncludeBinary "Image\Window\DownRight.png"
ImageWindowDown:
   IncludeBinary "Image\Window\Down.png"
ImageWindowDownLeft:
   IncludeBinary "Image\Window\DownLeft.png"
ImageWindowLeft:
   IncludeBinary "Image\Window\Left.png"
ImageWindowCenter:
   IncludeBinary "Image\Window\Center.png"
ImageWindowMin:
   IncludeBinary "Image\Window\Min.png"
ImageWindowMax:
   IncludeBinary "Image\Window\Max.png"
ImageWindowClose:
   IncludeBinary "Image\Window\Close.png"
ImageWindowEnd:

EndDataSection

















; IDE Options = PureBasic 5.11 (Windows - x64)
; CursorPosition = 275
; FirstLine = 81
; Folding = Dg9
; EnableAsm
; EnableUnicode
; EnableXP
; Executable = dd0.exe
; HideErrorLog
; CompileSourceDirectory